package org.ilovecode.display {
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.ilovecode.events.MenuEvent;
	import org.ilovecode.mvc.View;
	import org.ilovecode.screen.ScreenGroup;
	import org.ilovecode.screen.ScreenName;
	
	/**
	 * ...
	 * @author Vjekoslav Ratkajec
	 */
	public class BasicScreen extends View {
		
		//{ region Stage elements
		
		public var logo:SimpleButton;
		public var searchBox:SearchBox;
		public var mainMenu:MainMenu;
		public var mainMenuBusiness:MainMenuBusiness;
		public var switchApartmentButton:SimpleButton;
		public var switchBusinessButton:SimpleButton;
		
		//} endregion
		
		private var _mode:String = "";
		
		public function BasicScreen() {
			super("basicScreen");
		}
		
		override protected function addListeners():void
		{
			super.addListeners();
			mainMenu.addEventListener(MenuEvent.CLICK, handle_Click);
			mainMenuBusiness.addEventListener(MenuEvent.CLICK, handle_Click);
			logo.addEventListener(MouseEvent.CLICK, handle_Click);
			switchApartmentButton.addEventListener(MouseEvent.CLICK, handle_Click);
			switchBusinessButton.addEventListener(MouseEvent.CLICK, handle_Click);
		}
		
		override protected function removeListeners():void
		{
			super.removeListeners();
			mainMenu.removeEventListener(MenuEvent.CLICK, handle_Click);
			mainMenuBusiness.removeEventListener(MenuEvent.CLICK, handle_Click);
			logo.removeEventListener(MouseEvent.CLICK, handle_Click);
			switchApartmentButton.removeEventListener(MouseEvent.CLICK, handle_Click);
			switchBusinessButton.removeEventListener(MouseEvent.CLICK, handle_Click);
		}
		
		protected function handle_Click(event:Event):void
		{
			switch(event.target)
			{
				case mainMenu:
					//Fallthrough
				case mainMenuBusiness:
					//this.dispatchEvent(event);
					break;
				case logo:
					//this.dispatchEvent(new MenuEvent(MenuEvent.CLICK, "logo"));
					controller.showScreen(ScreenName.INTRO);
					break;
				case switchApartmentButton:
					setMenuMode(ScreenGroup.APARTMENTS);
					break;
				case switchBusinessButton:
					setMenuMode(ScreenGroup.BUSINESS);
					break;
				default:
					break;
			}
		}
		
		public function setMenuMode(mode:String):void {
			model.group = mode;
			_mode = mode;
			mainMenu.visible = switchBusinessButton.visible = (mode == ScreenGroup.APARTMENTS);
			mainMenuBusiness.visible = switchApartmentButton.visible = (mode == ScreenGroup.BUSINESS);
			//this.dispatchEvent(new MenuEvent(MenuEvent.CLICK, mode));
			controller.showScreen(ScreenName.RENDER);
		}
		
		public function get mode():String {
			return _mode;
		}
		
	}

}